package com.huipinche.dao.impl;

import com.huipinche.dao.JourneyDao;
import com.huipinche.dao.JourneyFormDao;
import com.huipinche.dao.bean.Journey;
import com.huipinche.dao.bean.JourneyForm;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Auther: 王勇杰/张凯霄
 * @Date:
 * @Description:
 */
public class JourneyDaoimpl implements JourneyDao {
    static List<Journey>journeyData;//Object  int-> Integer
    static List<Journey> journeys;
    static List<Journey> journeys01;
    static int jid = 0;
    static {
        journeyData = new ArrayList<>();//多态
        journeys = new ArrayList<>();
        journeys01 = new ArrayList<>();
    }

    @Override
    public int insertJourney(Journey journey) {
        jid++;
        journey.setId(jid);//*
        journeyData.add(journey);
//        System.out.println("我被写入数据了");
        System.out.println(journey.toString());
        return 1;
    }

    @Override
    public int deleteJourney(int id) {
        int flag=0;//计数器
        for(int i=0;i<journeyData.size();i++ ){
            if(journeyData.get(i).getId()==id){
                journeyData.remove(i);
                flag++;
            }
            return flag;
        }
        return 0;
    }

    @Override
    public int deleteJourneyByFlag() {
        int flag = 0;//计数器
        for(int i=0;i<journeyData.size();i++ ){
            if(journeyData.get(i).getJourneyflag()==4){
                journeyData.remove(i);//注意使用方法！！！
                flag++;
            }
            return flag;
        }

        return 0;
    }

    @Override
    public List<Journey> seletJourneyByTime(Date time) {

        for(int i=0;i<journeyData.size();i++ ){
//            System.out.print("持久层里面222");
            if(journeyData.get(i).getJourneytime().equals(time)){
//                System.out.print("持久层里面333");
                journeys.add(journeyData.get(i));
            }

        }

        return journeys;
    }

    @Override
    public List<Journey> seletJourneyByStartadd(String startadd) {
//        System.out.print("持久层里面111");
        for(int i=0;i<journeyData.size();i++ ){
//            System.out.print("持久层里面222");
//            System.out.print("\n");
//            System.out.print(journeyData.get(i).getStartadd());
//            System.out.print("\n");
//            System.out.print(startadd);
//            System.out.print("\n");
//            System.out.print(journeyData.get(i).getStartadd().equals(startadd));
//            System.out.print("\n");
            if(journeyData.get(i).getStartadd().equals(startadd) ){
//                System.out.print("持久层里面333");
                journeys01.add(journeyData.get(i));
            }

        }
        return journeys01;
    }

    @Override
    public List<Journey> seletJourneyAll() {

        return journeyData;//????
    }
}
